package com.charles.springcloud.service.impl;

import com.charles.springcloud.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;


import java.util.UUID;

/**
 * @Author: 风中灵劲草
 * @Date: 2021/08/19/16:02
 * @Description:
 */
@EnableBinding(Source.class)  //定义消息推送通道
public class MessageServiceImpl implements IMessageService {

    @Autowired
    private MessageChannel output;   //消息发送通道

    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("****serial"+ serial);
        return serial;
    }
}
